import request from "@/utils/request";
import { queryParams } from '@/utils/utils'
// 商品列表 http://ceshi13.dishait.cn/admin/goods/:page?tab=all&title=关键词&category_id=2&limit=10

export const getGoodsList = ({ page, tab, limit, title, category_id }) => {
    let r = queryParams({ tab, limit, title, category_id })
    return request({
        url: `/goods/${page}${r}`,
        method: "get",
    });
};

// 上架 下架 data={ids:[],status:0/1}
export const changGoodsStatus = (status, ids) => {
    ids = Array.isArray(ids) ? ids : [ids]
    return request({
        url: `/goods/changestatus`,
        method: "POST",
        data: {
            ids,
            status
        }
    });


};

// 添加内容

export const addGoods = (data) => {
    return request({
        url: `/goods`,
        method: "POST",
        data,
    });
};
// 修改内容
export const editGoods = (id, data) => {
    return request({
        url: `/goods/${id}`,
        method: "POST",
        data,
    });
};
// 删除
export const delGoods = (ids) => {
    ids = Array.isArray(ids) ? ids : [ids]
    return request({
        url: `/goods/delete_all`,
        method: "POST",
        data: {
            ids
        }
    });
};
export const recoveryGoods = (data) => {
    return request({
        url: `/goods/restore`,
        method: "POST",
        data
    });
};
// 彻底删除 goods/destroy
export const destroyGoods = (data) => {
    return request({
        url: `/goods/destroy`,
        method: "POST",
        data
    });
};
// 审核商品 

export const checkGoods = (id, data) => {
    return request({
        url: `/goods/${id}/check`,
        method: "POST",
        data
    });
};
// 设置轮播图 goods/banners/:id
export const setGoodsBanners = (id, data) => {
    return request({
        url: `goods/banners/${id}`,
        method: "POST",
        data
    });
};

// 查看商品资料 goods/banners/:id
export const readGoods = (id) => {
    return request({
        url: `goods/read/${id}`,
        method: "get",
    });
};

// 更新商品规格 goods/updateskus/:id
export const updateskusGoods = (id, data) => {
    return request({
        url: `goods/updateskus/${id}`,
        method: "POST",
        data
    });
};

// 添加商品规格选项
export const addSkuGoods = (data) => {
    return request({
        url: `goods_skus_card`,
        method: "POST",
        data
    });
};
// 删除商品规格选项
export const delSkuGoods = (id, data) => {
    return request({
        url: `goods_skus_card/${id}/delete`,
        method: "POST",
        data
    });
};
// 修改商品规格选项
export const editSkuGoods = (id, data) => {
    return request({
        url: `goods_skus_card/${id}`,
        method: "POST",
        data
    });
};
// 排序商品规格选项 /goods_skus_card/sort
// 添加商品规格选项的值 goods_skus_card_value
export const addSkuValue = (data) => {
    return request({
        url: `goods_skus_card_value`,
        method: "POST",
        data
    });
};
// 修改商品规格选项的值 /goods_skus_card_value/:id
export const editSkuValue = (id, data) => {
    return request({
        url: `goods_skus_card_value/${id}`,
        method: "POST",
        data
    });
};
// 删除商品规格选项的值 goods_skus_card_value/:id/delete
export const delSkuValue = (id, data) => {
    return request({
        url: `goods_skus_card_value/${id}/delete`,
        method: "POST",
        data
    });
};
// 选择设置商品规格选项和值 goods_skus_card/:id/set

export function chooseAndSetGoodsSkusCard(id, data) {
    return request({
        url: `goods_skus_card/${id}/set`,
        method: "POST",
        data
    });
}